package com.rrd.dw.mr.gzip.kafka;

import java.io.IOException;
import java.util.regex.Pattern;
import java.util.Date;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import com.ucredit.babel.common.model.Job;
import com.ucredit.babel.common.model.qcloud.QCloudAntiFraud;
import com.ucredit.babel.common.model.qcloud.QcloudAntiFraudRecords;
import com.rrd.dw.utils.DateUtil;

/**
 *
 * @author zhangjunjian
 */
@Deprecated
public class QcloudAntifraudParse {
    public static final String CRT001 =  "\001";
    public static final Pattern CRT001_PATTERN =  Pattern.compile("\001");
    private String job_id ="";
    private String timestamstr="";
    private StringBuilder sb = new StringBuilder(500);
    private  Text val = new Text();
    private  Text key= new Text();
    
    /**
     * 新网银行风控结果数据
     * @param QcloudAntiFraudRecords
     * @throws InterruptedException
     * @throws IOException
     */
    public  void parseQcloudAntifraud(Context context,QcloudAntiFraudRecords qcloudantifraudRecords,String successful) throws IOException, InterruptedException{
        new StringBuilder(200);
        Job job = qcloudantifraudRecords.getJob();
        QCloudAntiFraud antiFraud = qcloudantifraudRecords.getAntiFraud();

        sb.delete(0,sb.length());
        //job_id
        this.job_id = job.getJobID()==null?"":job.getJobID();
        this.timestamstr=qcloudantifraudRecords.getTimestamp()==null?"":DateUtil.formateDateStr(new Date(qcloudantifraudRecords.getTimestamp()));
        sb.append(job_id).append(CRT001).append(timestamstr).append(CRT001).append(qcloudantifraudRecords.getIdNumber()).append(CRT001);
        //响应http状态 "name", "certtype",  "reason", "createtype","data"
        sb.append(job.getSystemID()==null?"":job.getSystemID()).append(CRT001);

        sb.append(antiFraud.getColumnFamilyName()==null?"":antiFraud.getColumnFamilyName()).append(CRT001);
        //
        sb.append(antiFraud.getCode()==null?"":antiFraud.getCode()).append(CRT001);

        sb.append(antiFraud.getMessage()==null?"":antiFraud.getMessage()).append(CRT001);

        sb.append(antiFraud.getData()==null?"":antiFraud.getData());

        key.set("qcloud_data");
        val.set(sb.toString().replace("\n", " "));
        context.write(key, val);
    }


}
